/*
    RExLib project, file uabstractsocket.h
    Copyright (C) 2012  Sarvaritdinov Ravil ra9oaj@gmail.com

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/


#ifndef UABSTRACTSOCKET_H
#define UABSTRACTSOCKET_H

#include <unistd.h>
#include <stdint.h>

namespace rex {

class RAbstractSocket
{
public:
  enum Status
    {
        RS_UNCONNECT,
        RS_HOSTLOOKUP,
	RS_CONNECTING,
        RS_CONNECTED,
        RS_DISCONNECTED,
        RS_ERROR
    };

    enum Error
    {
        RE_NONE,
        RE_CREATESOCKET,
	RE_HOSTLOOKUP,
	RE_CONNECTION,
        RE_HOSTNOTFOUND,
        RE_REJECTCONNECTION,
        RE_TIMEOUT,
        RE_WRITE,
        RE_READ,
	RE_ADDRESS,
	RE_ADDRESSFAMILY,
	RE_PROTOCOLFAMILY,
	RE_SOCKFD
    };

    enum AddressFamily
    {
        RS_UNIX,
        RS_INET,
        RS_INET6,
	RS_AUTO
    };

    enum AddressFormat
    {
	RS_NUMERIC,
	RS_DOMAIN,
	RS_USER
    };

    enum ProtocolFamyly
    {
        RS_STREAM,
        RS_DGRAM,
        RS_RAW
    };

    virtual uint16_t port() const = 0;
    virtual const char* host( AddressFormat format ) const = 0;
    virtual int socketFd() const = 0;
    virtual bool setSocketFd ( const int &sockfd ) = 0;
    virtual bool connectToHost ( const char* host, const uint16_t &prt ) = 0;
    virtual void closeSocket() = 0;
    virtual void setNonBlock(bool flag = true) = 0;
    //virtual void setSocketLayer(UAbstractSocket::AddressFamily _sl) = 0;
    virtual int status() = 0;
    virtual int error() const = 0;
    virtual size_t write ( const char* buf, int len ) = 0;
    virtual char* read ( int len = 0 ) = 0;
    virtual size_t read ( char* buf, int len ) = 0;
    virtual size_t bytesAvailable() const = 0;
    virtual void clear() = 0;

};

}
#endif // UABSTRACTSOCKET_H
